Button |
A push button is a component that contains a label and that generates an event when it is pressed.it has two constructors. |
WRITE A PROGRAM ON BUTTONS.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Buttons extends Applet implements ActionListener
{
String s=" ";
public void init()
{
Button b1=new Button("Vision");
Button b2=new Button("Computers");
Button b3=new Button("Mainroad");
Button b4=new Button("Vuyyuru");
add(b1);
add(b2);
add(b3);
add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String st=ae.getActionCommand();
if(st.equals("Vision"))
{
s="You pressed Vision.";
}
else
if(st.equals("Computers"))
{
s="You pressed Computers.";
}
if(st.equals("Mainroad"))
{
s="You pressed Mainroad.";
}
else
if(st.equals("Vuyyuru"))
{
s="You pressed vuyyuru.";
}
repaint();
}
public void paint(Graphics g)
{
g.drawString(s,60,100);
}
}
/*<applet code=Buttons width=300 height=130>
</applet>*/